home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / prolog / sbprolog / v3 / cmplib_s.lha / cmplib_src / $tprog1.P < prev    next >
Text File  |  1990-04-12  |  17KB  |  471 lines

  1. /************************************************************************
  2. *                                    *
  3. * The SB-Prolog System                            *
  4. * Copyright SUNY at Stony Brook, 1986; University of Arizona, 1987    *
  5. *                                    *
  6. ************************************************************************/
  7.  
  8. /*-----------------------------------------------------------------
  9. SB-Prolog is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY.  No author or distributor
  11. accepts responsibility to anyone for the consequences of using it
  12. or for whether it serves any particular purpose or works at all,
  13. unless he says so in writing.  Refer to the SB-Prolog General Public
  14. License for full details.
  15.  
  16. Everyone is granted permission to copy, modify and redistribute
  17. SB-Prolog, but only under the conditions described in the
  18. SB-Prolog General Public License.   A copy of this license is
  19. supposed to have been given to you along with SB-Prolog so you
  20. can know your rights and responsibilities.  It should be in a
  21. file named COPYING.  Among other things, the copyright notice
  22. and this notice must be preserved on all copies. 
  23. ------------------------------------------------------------------ */
  24. /* $tprog1.P */
  25.  
  26. /* This program is the beginning of an attempt to write a translator that
  27. will take a preprocessed prolog program and produce a list of PIL
  28. instructions that implements the program.  The preprocessor adds pragma
  29. information to the program to make it possible for it to be processed.  We
  30. use the following representation: 
  31.  
  32.   preddef(Name,Arity,Clauses,Pragma,Exrefs)
  33.     where
  34.     Name is the predicate name.
  35.     Arity is the arity of the predicate.
  36.     Clauses is a list of clause terms that represent the defining rules.
  37.     Pragma is a list, empty for the moment.
  38.     Exrefs is a list (with tail a var) of external references: 
  39.       er(Predname,Ep) where Ep is the entry point addr of predicate
  40.       Predname.
  41.  
  42.   clause(Args,Clause,Pragma)
  43.     where
  44.     Args is a list of the formal parameters in the head of the clause.
  45.       (Arity long).
  46.     Clause is a term representing the literals on the rhs of the rule.
  47.     Pragma is a list; s(_,_) is a symbol table with information
  48.       concerning the variables that appear in the clause. 
  49.       all(y) indicates alloc-dealloc is necessary, all(n) indicates 
  50.       it's not nec.
  51.  
  52. A clause is represented as a term with structure symbols
  53. and(Firstconjunct,Pragma,Secondconjunct),
  54. or(Firstdisjunct,Pragma,Seconddisjunct), not(Negformula,Pragma), or nil if
  55. it is empty.  Goals on the right hand side are represented as:
  56.  
  57. '_call'(Predname,Arglist,Pragma):
  58.     where
  59.     Predname is the predicate name.
  60.     Arglist is the list of arguments.
  61.     Pragma is the pragma; nv(N) means that N is the size of the 
  62.       activation record at this point.
  63.  
  64. For example p(a,b) is represented as '_call'(p,[[a],[b]],[nv(1)]).
  65. Structure and constants are represented as lists, not as normal structures.
  66. Thus f(a,b) would be represented as [f,[a],[b]].  Constants are represented
  67. as 0-ary structures, i.e., lists of length one.  Variables are represented
  68. using v(Vid,Pragma), where Vid is a constant symbol representing the name,
  69. and Pragma is a list.  In the pragma, d(L) indicates that L is the location
  70. in the AR of this variable (or its register if it is a temporary) ; occ(f)
  71. indicates that this is the first occurrence and occ(s) a subsequent
  72. occurrence; k(t) indicates it is a temporary variable, k(p) indicates a
  73. permanent variable, k(u) indicates an unsafe occurrence of a permanent
  74. variable.  k(vh) indicates a void (anonymous) variable occurring at the top
  75. level in the head of a clause, k(vb) indicates a void variable occurring at
  76. the top level in the body of a clause.  */
  77.  
  78. /* For the clauses:
  79.     p(X,a) :- r(Y,X),s(Y,f(g(g(X)),f(Y,b))).
  80.     p(B,c).
  81.     p(f(a,g(X)),f(g(a),X)).
  82.  
  83. The query is:
  84.  
  85. tpred(preddef(p,
  86.        2,
  87.        [clause([v(x,[k(p),d(2),occ(f)]),[a]],
  88.            and('_call'(r,
  89.                 [v(y,[k(p),d(3),occ(f)]),
  90.                  v(x,[k(p),d(2),occ(s)])],
  91.                 [nv(2)]),
  92.                [],
  93.                '_call'(s,
  94.                 [v(y,[k(u),d(3),occ(s)]),
  95.                  [f,[g,[g,v(x,[k(p),d(2),occ(s)])]],
  96.                 [f,v(y,[k(p),d(3),occ(s)]),[b]]]],
  97.                 [nv(2)])
  98.               ),
  99.            [all(y)]),
  100.         clause([v(b,[k(t),d(1),occ(f)]),[c]],nil,[nv(0),all(n)]),
  101.         clause([[f,[a],[g,v(x,[k(t),d(3),occ(f)])]],
  102.             [f,[g,[a]],v(x,[k(t),d(3),occ(s)])]],
  103.            nil,
  104.            [all(n)])
  105.        ],
  106.        []),
  107.       Label,
  108.       Pil,[],Exref).
  109.  
  110. */
  111.  
  112. /* ----------------------------------------------------------------------
  113.  
  114.    change to pragma representation for variables : for greater efficiency,
  115.    the Pragma information for variables is being represented as a term,
  116.    "vrec(Type,Occ,Loc,Misc)" where Type is the type of the variable (k(T)
  117.    in old representation), Occ indicates whether this is a first or
  118.    subsequent occurrence (occ(Occ) of older representation), Loc gives the
  119.    location of the variable (d(Loc) in old representation), and Misc stores
  120.    other information as a list.
  121.  
  122.    - saumya debray, july 8 1985
  123.    ---------------------------------------------------------------------- */
  124.  
  125. /* **********************************************************************
  126. $tprog1_export([$tprog/3]).
  127.  
  128. $tprog1_use($index1,[$index/7]).
  129. $tprog1_use($blist,[$append/3,_,$member1/2]).
  130. $tprog1_use($meta,[_,_,$length/2]).
  131. $tprog1_use($computil1,[$reserve/3,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_]).
  132. $tprog1_use($inline1,[$inline/2]).
  133. $tprog1_use($geninline1,[$geninline/7]).
  134. $tprog1_use($tgoal1,[_,$tpar/8,$tgoalargs/7]).
  135. $tprog1_use($glob,[_,$gennum/1,_]).
  136. $tprog1_use($aux1,[_,_,_,_,_,_,$disj_targ_label/2,_,_]).
  137. $tprog1_use($tcond1,[$tcond/7]).
  138. $tprog1_use($listutil1,[_,$merge/3,_,_,_,_,_,_]).
  139. $tprog1_use($disjunc1,[$disj_branch/8,$optimize_CP/2]).
  140. ********************************************************************** */
  141.  
  142.  
  143. /* $tprog(Progdef,Pil,Pilr) is true if the translation of the Progdef (a
  144. list of Predicates) is the difference list Pil-Pilr.            */
  145.  
  146. $tprog([],Pil,Pil,_).
  147. $tprog([Preddef|Prog],Pil,Pilr,Prag) :-
  148.     $tpred(Preddef,Pil,Pilr1,Prag),
  149.     $tprog(Prog,Pilr1,Pilr,Prag).
  150.  
  151. /* $tpred(Preddef,Label,Pil,Pilr) is true if the translation of Preddef
  152. is the difference list Pil-Pilr, with entry point Label. $tpred loops
  153. through the clauses.  */
  154.  
  155. $tpred(preddef(Pname,Arity,[Oneclause],P),Pil,Pilr,_) :- !,
  156.     ($comp_builtin(Pname,Arity,_) ->
  157.     $umsg(['*** Warning: redefining builtin ',Pname,'/',Arity]) ;
  158.     true
  159.     ),
  160.     $tclause(Oneclause,P,Pil,Pilr,0).
  161. $tpred(preddef(Pname,Arity,CList,P),Pil,Pilr,Prag) :- 
  162.     ($comp_builtin(Pname,Arity,_) ->
  163.         $umsg(['*** Warning: redefining builtin ',Pname,'/',Arity]) ;
  164.         true
  165.     ),
  166.     $index(Pname,Arity,CList,P,Pil,Pil0,Prag,SwList),
  167.     $length(CList,N),
  168.     ((N =< 3, not($member2(trace,Prag)), $tail_rec(CList,Pname,Arity)) ->
  169.         $get_indexinst(Pil,IndList) ;
  170.         IndList = []
  171.     ),
  172.     $tclauses(CList,P,Pil1,Pilr,SwList),
  173.     ((IndList = [Inst|_],
  174.       (Inst ?= switchonterm(_,_,_) ; Inst ?= switchonlist(_,_,_))
  175.      ) ->
  176.         $subst_exec(Pil1,Pname,Arity,IndList,Pil0,Pilr) ;
  177.         Pil1 = Pil0
  178.     ).
  179.  
  180. /* $tclauses generates retry and trust instructions for each clause */
  181.  
  182. $tclauses([],_,Pil,Pil,_).
  183. $tclauses([Clause|Restclauses],PredPrag,Pil,Pilr,SwList) :- 
  184.     $tclause(Clause,PredPrag,Pil,Pil1,SwList),
  185.     $tclauses(Restclauses,PredPrag,Pil1,Pilr,SwList).
  186.  
  187.  
  188. /* $tclause(Clause,Pil,Piltail) is true if Pil-Piltail is the code that
  189. translates clause Clause. */
  190.  
  191. $tclause(clause(Args,Body,Prag),PredPrag,[label(L)|Pil],Pilr,SwL) :- 
  192.     $member1(all(A),Prag),
  193.     $member1(label(L),Prag),
  194.     $length(Args,N),
  195.     $reserve(N, [], Tin), !,
  196.     $tprog_getnvars(Body,Nv), 
  197.     (SwL =:= 1 ->
  198.         $theadpars_swlist(Args,A,L,PredPrag,Nv,Pil,Pilr1,Tin,TRegs1) ;
  199.     ((A ?= y ->
  200.          Pil = [allocate(Nv)|Pil1] ;
  201.          Pil = Pil1
  202.      ),
  203.          $theadpars(Args,1,PredPrag,Pil1,Pilr1,Tin,TRegs1)
  204.     )
  205.     ),
  206.     $tbody(Body,A,Pilr1,Pilr,TRegs1,_,[]).
  207.  
  208. /* $theadpars_swlist loops through the formal parm list.  It's similar
  209.    to $theadpars, expect that it generates special code for the first
  210.    parameter, to handle the switchonlist instruction properly.       */
  211.  
  212. $theadpars_swlist([Arg1|ARest],A,L,PPrag,Nv,Pil,Pilr,Tin,Tout) :-
  213.      $tpar_swlist(Arg1,A,L,Nv,Pil,Pilm,Tin,Tmid),
  214.      $theadpars(ARest,2,PPrag,Pilm,Pilr,Tmid,Tout).
  215.  
  216. $tpar_swlist([[]],A,(P,N,L),Nv,Pil,Pilr,Tin,Tout) :-
  217.      $concat_atom(L,nil,L1),
  218.      $release(1,Tin,Tout),
  219.      (A = y ->
  220.          Pil = [label((P,N,L1)),allocate(Nv),getnil(1)|Pilr] ;
  221.         /* not worth optimizing away getnil if must allocate */
  222.     (L3 = (P,N,L4), $gennum(L4),
  223.           Pil = [getnil(1),label((P,N,L1))|Pilr]
  224.     )
  225.      ).
  226. $tpar_swlist(['.'|Args],A,(P,N,L),Nv,Pil,Pilr,Tin,Tout) :-
  227.      $concat_atom(L,lis,L1),
  228.      $release(1,Tin,Tmid),
  229.      L3 = (P,N,L4), $gennum(L4),
  230.      (A = y ->
  231.          (Pil = [allocate(Nv), getlist(1)|Pilm1],
  232.      Pilm2 = [allocate(Nv),getlist_k(1)|Pilm3]
  233.     ) ;
  234.     (Pil = [getlist(1)|Pilm1],
  235.      Pilm2 = [getlist_k(1)|Pilm3]
  236.     )
  237.      ),
  238.      (Args = [v(_,vrec(t,_,_,_)),v(_,vrec(t,_,_,_))] ->
  239.          ($tsubpars(h,Args,Pilm1,[jump(L3),label((P,N,L1))|Pilm2],Tmid,Tout),
  240.      $tsubpars(h,Args,Pilm3,[label(L3)|Pilr],Tmid,_)
  241.     ) ;
  242.     (Pilm1 = [jump(L3),label((P,N,L1))|Pilm2],
  243.      Pilm3 = [label(L3)|Pilm3a],
  244.      $tsubpars(h,Args,Pilm3a,Pilr,Tmid,Tout)
  245.     )
  246.      ).     
  247.  
  248. /* $theadpars loops through the formal parameter list */
  249.  
  250. $theadpars([],_,_,Pil,Pil,T,T).
  251.  
  252. /* TRin = list of temp registers in use at entry; TRout = list of temps
  253.    in use at exit.                            */
  254.  
  255. $theadpars([Par|Rest],N,PredPrag,Pil,Pilr,TRin,TRout) :-
  256.     $tpar(h,Par,N,Pil,Pil1,TRin,TRmid,PredPrag),
  257.     N1 is N+1,
  258.     $theadpars(Rest,N1,PredPrag,Pil1,Pilr,TRmid,TRout).
  259.  
  260. :- mode($tbody,7,[nv,d,d,d,d,d,d]).
  261.  
  262. $tbody(nil,_,[proceed|Pil],Pil,T,T,_) :- !.
  263. $tbody('_call'(Pred,Args,CPrag),A,Pil,Pilr,Tin,Tout,HoldRegs) :-    
  264.     $tbodycall(Args,A,Pil,Pilr,Tin,Tout,HoldRegs,Pred,CPrag).
  265. $tbody(and(Goal,_,Goals),A,Pil,Pilr,Tin,Tout,HoldRegs) :- 
  266.     $tbody(Goal,A,Pil,Pil1,Tin,Tmid,HoldRegs),
  267.     $tbody(Goals,A,Pil1,Pilr,Tmid,Tout,HoldRegs).
  268. $tbody(if_then_else(Test,P,TGoal,FGoal),A,Pil,Pilr,Tin,Tout,Hold0) :-
  269.     $gen_label(TLabel), $gen_label(FLabel), $gen_label(After),
  270.     $member1(tvars(TV),P),
  271.     $append(TV,Hold0,Hold1),
  272.     $tcond(Test,TLabel,FLabel,Pil,[label(TLabel)|Pilm1],Tin,Tmid,Hold1),
  273.     $tbody(TGoal,A,Pilm1,[jump(After),label(FLabel)|Pilm2],Tmid,Tout0,Hold1),
  274.     $merge(Tmid,Tout0,Tout1),
  275.     $tbody(FGoal,A,Pilm2,[label(After)|Pilr],Tout1,Tout2,Hold0), /* tvar may be in */
  276.     $merge(Tout1,Tout2,Tout), !.        /* branches of an i-t-e */
  277. $tbody(or(Goal,_,Goals),A,Pil,Pilr,Tin,[],Hold) :-
  278.     $tprog_getnvars(Goal,Nv),
  279.     $gen_label(DLabel), arg(1,DLabel,D),
  280.     $gen_label(NDisj), $gen_label(After),
  281.     XPil = [call(D,-1,Nv),label(DLabel),trymeelse(NDisj,0)|Pilm1],
  282.     $tbody(Goal,A,Pilm1,Pilm2,Tin,_,Hold),
  283.     Pilm2 = [jump(After),label(NDisj),trustmeelsefail(0)|Pilm3],
  284.     $tbody(Goals,A,Pilm3,[label(After)|Pilr],Tin,_,Hold),
  285.     $optimize_CP(XPil,Pil), !.
  286.  
  287. $tbodycall(Args,A,Pil,Pilr,Tin,Tout,Hold,Pred,CPrag) :-
  288.     $member1(lastlit,CPrag),
  289.     !,
  290.     $length(Args, Arity),
  291.     (($inline(Pred,Arity), 
  292.       ((A = y, Pil1 = [deallocate,proceed|Pilr]) ;
  293.        (A = n, Pil1 = [proceed | Pilr])
  294.       ),
  295.       $geninline(Pred,Args,Hold,Pil,Pil1,Tin,Tout)
  296.      ) ;
  297.      (((A = y, Pil1 = [deallocate,execute((Pred,Arity))|Pilr]) ;
  298.        (A = n, Pil1 = [execute((Pred,Arity)) | Pilr])
  299.       ),
  300.       $reserve(Arity,Tin,T1), Tout = [],
  301.       $tgoalargs(Args,1,Pil,Pil1,CPrag,T1,_)
  302.      )
  303.     ).
  304. $tbodycall(Args,_,Pil,Pilr,Tin,Tout,Hold,Pred,CPrag) :-
  305.     $length(Args, Arity),
  306.     (($inline(Pred,Arity),
  307.       $geninline(Pred,Args,Hold,Pil,Pilr,Tin,Tout)
  308.      ) ;
  309.      (($member1(nv(Nv), CPrag),
  310.        $reserve(Arity,Tin,T1), Tout = [],
  311.        $tgoalargs(Args,1,Pil,[call(Pred,Arity,Nv)|Pilr],CPrag,T1,_)
  312.       )
  313.      )
  314.     ).
  315.  
  316. $optimize_CP(XPil,XPil) :- var(XPil), !.
  317. $optimize_CP([Inst|Tail], [Inst|Tail]) :- var(Tail), !.
  318. $optimize_CP([trymeelse(L1,N),
  319.          call(D0,-1,_),
  320.          label((D0,-1,_)),
  321.          trymeelse(L2,N)|Xr],
  322.         [trymeelse(L2,N)|Pr]) :-
  323.     $optimize_CP_1(L1,L2,Xr,Pr1),
  324.     $optimize_CP_2(Pr1,Pr).
  325. $optimize_CP([trustmeelsefail(N),
  326.          call(D0,-1,_),
  327.          label((D0,-1,_)),         
  328.          trymeelse(L2,N)|Xr],
  329.         [retrymeelse(L2,N)|Xr]).
  330. $optimize_CP([Inst|XPRest],[Inst|PRest]) :-
  331.     $optimize_CP(XPRest,PRest).
  332.  
  333.  
  334. $optimize_CP_1(L1,L2,XPil,XPil) :- var(XPil).
  335. $optimize_CP_1(L1,L2,[label(L2),retrymeelse(L3,N)|XPRest],
  336.             [label(L2),retrymeelse(L3,N)|PRest]) :-
  337.         $optimize_CP_1(L1,L3,XPRest,PRest).
  338. $optimize_CP_1(L1,L2,[label(L2),trustmeelsefail(N)|XPRest],
  339.             [label(L2),retrymeelse(L1,N)|PRest]) :-
  340.         $optimize_CP_1(L1,L2,XPRest,PRest).
  341. $optimize_CP_1(L1,L2,[Inst|XPRest],[Inst|PRest]) :-
  342.         $optimize_CP_1(L1,L2,XPRest,PRest).
  343.  
  344.  
  345. $optimize_CP_2(Pil,Pil) :- var(Pil).
  346. $optimize_CP_2([trustmeelsefail(N),
  347.            call(D0,-1,_),
  348.            label((D0,-1,_)),
  349.            trymeelse(L1,N)|Rest],
  350.           [retrymeelse(L1,N)|Rest]).
  351. $optimize_CP_2([Inst|Rest],[Inst|Rest1]) :- $optimize_CP_2(Rest,Rest1).
  352.  
  353. :- mode($tprog_getnvars,2,[nv,d]).
  354.  
  355. $tprog_getnvars('_call'(_,_,CPrag), NVars) :-
  356.     (($member1(nv(NVars),CPrag),
  357.       (NVars = 0 ; true)) ;
  358.      NVars = 0
  359.     ).
  360. $tprog_getnvars(nil,0).
  361. $tprog_getnvars(and(Goal,_,_),NVars) :- $tprog_getnvars(Goal,NVars).
  362. $tprog_getnvars(or(Goal,_,_),NVars) :- $tprog_getnvars(Goal,NVars).
  363. $tprog_getnvars(not(Goal,_),NVars) :- $tprog_getnvars(Goal,NVars).
  364. $tprog_getnvars(if_then_else(_,_,Goal,_),NVars) :- $tprog_getnvars(Goal,NVars).
  365.  
  366. $get_indexinst(IList,IndexInst) :- 
  367.     var(IList) ->
  368.         IndexInst = [] ;
  369.         (IList = [Inst|IRest],
  370.          (Inst = label(_) ->
  371.             IndexInst = IndInstRest ; IndexInst = [Inst|IndInstRest]
  372.          ),
  373.          $get_indexinst(IRest,IndInstRest)
  374.         ).
  375.  
  376. $subst_exec(Pil,P,N,IList,Pil0,Pilr) :-
  377.     var(Pil) ->
  378.         Pil0 = Pilr ;
  379.         (Pil = [Inst|IRest],
  380.          (Inst = execute((P,N)) ->
  381.              (Pil0 = ['_$execmarker'|Pil0a],   /* '_$execmarker' tells the peephole */
  382.              $subst_exec1(IList,Pil0a,Pil1)   /*  optimizer that there was an "execute" */
  383.             ) ;                  /*  here.  The PO uses this info to  */
  384.             Pil0 = [Inst|Pil1]          /* when registers can be considered dead */
  385.          ),
  386.          $subst_exec(IRest,P,N,IList,Pil1,Pilr)
  387.         ).
  388.  
  389. $subst_exec1([],L,L).
  390. $subst_exec1([I|IRest],[I|LRest],L) :- $subst_exec1(IRest,LRest,L).
  391.  
  392. $tail_rec([clause(_,Body,_)|ClRest],P,N) :-
  393.     $tail_rec1(Body,P,N) ;
  394.     $tail_rec(ClRest,P,N).
  395.  
  396. $tail_rec1('_call'(P,Args,_),P,N) :- $length(Args,N).
  397. $tail_rec1(and(_,_,G),P,N) :- $tail_rec1(G,P,N).
  398. $tail_rec1(if_then_else(_,_,G1,G2),P,N) :- $tail_rec1(G1,P,N) ; $tail_rec1(G2,P,N).
  399. $tail_rec1(or(G1,_,G2),P,N) :- $tail_rec1(G1,P,N) ; $tail_rec1(G2,P,N).
  400.  
  401.  
  402. $tgoal('_call'(Pred,Args,Prag),Pil,Pilr,Tin,Tout) :-
  403.     $length(Args, Arity),
  404.     $inline(Pred,Arity),
  405.     !,
  406.     $geninline(Pred,Args,Prag,Pil,Pilr,Tin,Tout).
  407.  
  408. $tgoal('_call'(Pred,Args,Prag),Pil,Pilr,Tin,Tout) :-
  409.     $length(Args, Arity),
  410.     $member1(nv(Nvars),Prag),
  411.     $reserve(Arity,Tin,T1),
  412.     $tgoalargs(Args,1,Pil,[call(Pred,Arity,Nvars)|Pilr],Prag,T1,Tout).
  413.  
  414. /* loops through args */
  415. $tgoalargs([],_,Pil,Pil,_,T,T).
  416. $tgoalargs([Arg|Args],N,Pil,Pilr,Prag,Tin,Tout) :-
  417.     $tpar(b,Arg,N,Pil,Pil1,Tin,T1,[]),
  418.     N1 is N + 1,
  419.     $tgoalargs(Args,N1,Pil1,Pilr,Prag,T1,Tout).
  420.  
  421. /* generates gets,puts,blds,unis for a par*/
  422.  
  423. :- index($tpar,8,2).
  424.  
  425. $tpar(W,[Cid],N,Pil,Pilr,Tin,Tout,PredPrag) :- 
  426.     $coninst(W,Cid,N,Pil,Pilr),
  427.     (W = h -> $release(N,Tin,Tout) ; Tin = Tout).
  428.  
  429. $tpar(h,v(Vid,Prag),N,Pil,Pil,Tin,Tout,_) :-
  430.     $type(Prag,vh),        /* ignore void variables in head */
  431.     $release_if_done(Vid,N,Prag,[],Tin,Tout).
  432.  
  433. $tpar(W,v(Vid,Prag),N,Pil,Pilr,Tin,Tout,PredPrag) :-
  434.      Prag = vrec(T,L,Loc,_),
  435.      ((W = h, $release_if_done(Vid,N,Prag,[],Tin,Tmid)) ; Tin = Tmid),
  436.      ((T = t, $alloc_reg1(Prag,N,Tmid,Tout)) ; Tmid = Tout),
  437.      $varinst(W,L,T,Loc,N,Pil,Pilr,Tout).
  438.  
  439. $tpar(W,[Sid|Args],N,[Inst|Pil],Pilr,Tin,Tout,Prag) :-
  440.     Args=[_|_],
  441.     $length(Args,Arity),
  442.     $strinst(W,(Sid,Arity),N,Inst),
  443.     (W = h -> $release(N,Tin,Tmid) ; Tmid = Tin),
  444.     $tsubpars(W,Args,Pil,Pilr,Tmid,Tout).
  445.  
  446. /* loops through sub fields of a par */
  447. :- index($tsubpars,6,2).
  448.  
  449. $tsubpars(_,[],Pil,Pil,T,T).
  450. $tsubpars(W,[Subpar|Subpars],Pil,Pilr,T1,T2) :-
  451.     $tsubpar(W,Subpar,Pil,Pil1,T1,T3),
  452.     $tsubpars(W,Subpars,Pil1,Pilr,T3,T2).
  453.  
  454. /* generates code for a subfield of par */
  455. :- index($tsubpar,6,2).
  456.  
  457. $tsubpar(W,v(Vid,Prag),Pil,Pilr,Tin,Tout) :-
  458.     $alloc_reg(Prag,Tin,Tmid),
  459.     $occ(Prag,L),  $loc(Prag,Loc), $type(Prag,T),
  460.     $varsubinst(W,L,T,Loc,Pil,Pilr,Tmid),
  461.     ((T = t, $release_if_done(Vid,Loc,Prag,[],Tmid,Tout)) ;
  462.      Tmid = Tout
  463.     ).
  464.  
  465. $tsubpar(W,[Cid],[Inst|Pilr],Pilr,T,T) :-
  466.     $consubinst(W,Cid,Inst).
  467.  
  468.  
  469.  
  470. /* end $tprog1.P *************************************************/
  471.